#include "threadPool.h"

int pwd(int netfd, const char* path, const char* username)
{
    char vitualPath[4096];

    //字符串匹配定位
    char buf[4096];
    sprintf(buf, "%s/", path);
    char* position = strstr(buf,username);
    position += strlen(username);
    if(*(position) == '/')
    {
        int i = 0;
        while((*position) != '\0')
        {
            vitualPath[i] = *position;
            i++;
            position++;
        }
        vitualPath[i] = '\0';
        printf("vitualPath = %s\n", vitualPath);
        train_t train;
        train.length = strlen(vitualPath);
        memcpy(train.data,vitualPath,train.length);
        int ret = send(netfd,&train,sizeof(train.length)+train.length,0);
        ERROR_CHECK(ret, -1, "send");
        //正确发送
        bzero(&train, sizeof(train));
        train.length = 1;
        memcpy(train.data, "0", train.length);
        send(netfd,&train,sizeof(train.length)+train.length,0);
    }else
    {
        char erro[] = "pwd failed.";
        train_t train;
        train.length = strlen(erro);
        memcpy(train.data,erro,train.length);
        send(netfd,&train,sizeof(train.length)+train.length,0);
        return 1;
    }
    return 0;
}